package com.flyee.controller.tools.cartoon.view
{
	import com.flyee.controller.tools.cartoon.control.CartoonSpriteManager;
	import com.flyee.controller.tools.cartoon.model.EquipObj;
	import com.flyee.utils.GCHleper;
	
	import flash.display.Sprite;

	public class CartoonSprite extends Sprite
	{
		public var cartoonArray:Array = null;
		private var myManager:CartoonSpriteManager = null;
		public var myDir:uint = 0;
		public var myType:uint = 0;
		public var myChildList:Array = new Array();
		public function CartoonSprite()
		{
			super();
		}
		public function addMyChild(t:EquipObj):void
		{
			myChildList.push(t);
			//this.addChild(t.myDisplayObj);
			getIndex(t)
		}
		public function removeMyChild(t:EquipObj):void
		{
			var tempLength:uint = this.myChildList.length;
			for(var i:int = 0; i< tempLength;i++)
			{
				if(this.myChildList[i] == t)
				{
					myChildList.splice(i,1);
					if(this.contains(t.myDisplayObj))
					{
						this.removeChild(t.myDisplayObj);
					}
				}
			}
		}
		public function getIndex(t:EquipObj):uint
		{
			var tempLength:uint = this.myChildList.length;
			if(this.numChildren > 0)
			{
				var tempMinDepth:uint = 0
				for(var i:int = 0; i < tempLength; i++)
				{
					var temp:EquipObj = this.myChildList[i];
					if(temp.index > t.index)
					{
						tempMinDepth++;
					}
				}
				if(tempMinDepth != tempLength)
				{
					this.addChildAt(t.myDisplayObj,tempMinDepth);
				}
				else
				{
					this.addChild(t.myDisplayObj);
				}
			}
			else
			{
				this.addChild(t.myDisplayObj);
			}
			return tempMinDepth
		}
		public function clear():void
		{
			GCHleper.clearAll(this);
			if(this.cartoonArray)
			{
				this.cartoonArray.splice(0);
			}
			if(this.myChildList)
			{
				this.myChildList.splice(0);
			}
			this.myManager = null;
		}
		
	}
}